package com.highcom.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Component("myAdvice")
public class AOPAdvice {

    public void before(JoinPoint jp){
        //通过joinpoint参数获取调用原始方法锁携带的参数
        Object[] args = jp.getArgs();
        System.out.println("before..." + args[0]);
    }

    public void after(JoinPoint jp){
        Object[] args = jp.getArgs();
        System.out.println("after..." + args[0]);
    }
    public void afterReturning(Object ret){

        System.out.println("afterReturning..." + ret);
    }

    public void afterThrowing(Throwable t){

        System.out.println("afterThrowing..." + t);
    }

    public Object around(ProceedingJoinPoint pjp){
        //前置通知
        System.out.println("around before ... ");
        Object ret = null;
        //对原始方法的调用
        try {
            ret = pjp.proceed();
        } catch (Throwable e) {
            System.out.println("around exception  " + e.getMessage());
        }
        System.out.println("around after ... " + ret);
        return ret;
    }


}
